﻿using Util.Database;

namespace AutoNZBLoader
{
    class Program
    {
        private static void Main()
        {
            DB.Open(System.Configuration.ConfigurationSettings.AppSettings["DBProvider"], System.Configuration.ConfigurationSettings.AppSettings["ConnStr"]);
            try
            {
                DB.Cleanup();
                foreach (RSSFeed f in RSSFeed.Feeds)
                {
                    foreach (FeedItem fi in f.Items)
                    {
                        foreach (Request r in Request.Requests)
                        {
                            if (r.Matches(fi))
                            {
                                if (!r.IsAlreadyDownloaded(fi.Season, fi.Episode))
                                {
                                    fi.DownloadNZB(r);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            finally
            {
                DB.Close();
            }
        }
    }
}